public class CompletePack {
    private static final int N = 8;
    private static int[] fPlus = new int[N];
    private static int[] fk = new int[N];
    private static int[] weight = {0, 3, 4, 2};
    private static int[] v = {0, 4, 5, 3};

    public static int compPack(int W, int n) {
        for(int i = 1; i <= n; i++) {
            for(int j = weight[i]; j <= W; j++) {
                fPlus[j] = Math.max(fPlus[j], fPlus[j - weight[i]] + v[i]);
            }
            System.out.println(Arrays.toString(fPlus));
        }
        return fPlus[W];
    }

    public static void main(String[] args) {
        int n = 3;
        int W = 7;
        System.out.println("重量：" + Arrays.toString(weight));
        System.out.println("价值：" + Arrays.toString(v));
        int maxV = compPack(W, n);
        System.out.println("最大价值为：" + maxV);
    }
}